package com.example.springbootblog.service;


import com.example.springbootblog.mapper.BlogInfoMapper;
import com.example.springbootblog.mapper.UserInfoMapper;
import com.example.springbootblog.model.BlogInfo;
import com.example.springbootblog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;

    @Autowired
    BlogInfoMapper blogInfoMapper;
    public UserInfo queryByName(String userName) {
        return userInfoMapper.queryByName(userName);
    }

    public UserInfo getUserInfo(Integer userId) {
        return userInfoMapper.queryById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        // 根据博客 id 拿到博客信息
        BlogInfo blogInfo = blogInfoMapper.getBlogById(blogId);

        return userInfoMapper.queryById(blogInfo.getUserId());
    }
}
